﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace IllustratedCsharp7_ch21
{
    static class MyDownloadString
    {
        public static void DoRun()
        {
            Task<int> t = CountCharactersAsync("http://www.baidu.com");
            t.Wait();   //等待任务结束
            Console.WriteLine($"The task has finished,returning value {t.Result}.");
        }
        private static async Task<int> CountCharactersAsync(string site)
        {
            string resutl = await new WebClient().DownloadStringTaskAsync(new Uri(site));
            return resutl.Length;
        }
    }
    class Chapt21_3_3Wait_for_the_task_synchronously_in_the_calling_method
    {
        static void Main()
        {
            MyDownloadString.DoRun();
        }
    }
}
